package com.liu.thredState_study;


public class StudentThread extends Thread{

    private RunThread runThread;

    public void setThread(RunThread runThread){
        this.runThread = runThread;
    }
    @Override
    public void run() {
        while (true){
            synchronized (runThread){
                if (runThread.getRun()){
                    System.out.println("学生正在跑---"+runThread.getNum());
                }else{
                    try {
                        System.out.println("休息-----");
                        runThread.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                //跑步
                runThread.setNum(runThread.getNum()+1);
                //每次跑五步就休息一下
                if (runThread.getNum() % 5 == 0 && runThread.getNum() != 0){
                    runThread.setRun(false);
                }
                try {
                    this.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}